<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>viator商品提醒配置信息</title>
    <script src="__PUBLIC__/jquery/jquery.min.js"></script>
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
    <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
</head>
<style>
    /*.page1{*/
        /*display: none;*/
    /*}*/
    .layui-input-block{
        /*margin-left: 40px;*/
    }
    .searchs{
        position: absolute;
        right: 200px;
    }
    .travel_list{
        height:200px;
        margin-left: 30px;
        margin-right: 30px;
        overflow-y: scroll;
    }

    .travel_tit{
        margin-left: 30px;
        margin-right: 30px;
    }
    .layui-table thead tr{
        background: #e6e6e6;
    }
    .page4-box{
        padding: 12px 16px;
    }
    .query-box{
        padding:20px 20px 10px 20px ;
        /*padding-top:20px;*/
        border: 1px solid #e6e6e6;
        min-height: 45px;
    }
    .selected_trip{
        border: 1px solid #e6e6e6;
    }
    .tripspan{
        margin-left: 40px;
        margin-right: 30px;
    }
    .tripspan span{
        line-height: 38px;
        background: #00a0e9;
        padding: 5px;
        border-radius: 10px;
        color: #fff;
    }
    .tag{
        float: left;
    }
    /*上一步下一步按钮居中*/
    .butcent{
        position: absolute;
        bottom: 20px;
        left: 40%;
        margin-left: 30%;
        width:20%;
        /*margin: 30px;*/
        padding: 30px;
    }

    .butcent2{
        margin-left: 70%;
        width:20%;
        padding: 30px;
    }

    .picturebut{
        /*background-color: #fbfdff;*/
        border: 1px solid #c0ccda;
        border-radius: 6px;
        box-sizing: border-box;
        font-size:22px;
        width:48%;
        height: 100%;
        margin-top:-10%;
        margin-left:-8%;
        cursor: pointer;
        line-height: 300px;
        vertical-align: top;
    }
    .page3{
        margin-left: 16%;
        margin-top: 20%;
    }
    .layui-form-select .layui-edge{
        display: none;
        right: 0;
    }
    th{
        text-align: left;
    }
    .layui-input{
        border-radius: 5px;
    }
    .layui-form-label{
        width:120px;
    }
    .layui-input-block{
        margin-left: 150px;
    }
    .layui-laydate-content>.layui-laydate-list {
        padding-bottom: 0px;
        overflow: hidden;
    }
    .layui-laydate-content>.layui-laydate-list>li{
        width:50%
    }

    .merge-box .scrollbox .merge-list {
        padding-bottom: 5px;
    }
    .settimedate{
        width: 160px !important;
    }
    .addPickUpBtn,addAssembleBtn,.delPickUpBtn,.delAssembleBtn,.uploadAssembleImg{
        margin-top: 4px;
    }
    .clear_float{
        overflow: auto;
        margin-left: 0;
        margin-bottom: 4px;
    }
    .addressbox{
        position: initial;
    }
    .colorRed{
        color:red;
    }
</style>
<body>

<!--客户信息的弹窗的内容数据-->
<div>
    <form class="layui-form " id="tripconfig" action="">
        <div class="page1">
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                <legend>viator商品配置信息</legend>
            </fieldset>
            <div class="layui-form-item ">
                <div>
                    <div id="map" style="margin:0 auto !important;width:600px;height:150px;overflow: hidden;background:#eee">
                        <img src="" width="600" height="300" alt="" style="margin-top: -75px">
                    </div>
                    <div class="layui-form-item layui-form-text"  style="margin-top: 10px">
                        <label class="layui-form-label">免费等待时长<br>（分钟）</label>
                        <div class="layui-input-block" style="max-width:500px;">
                            <input placeholder="例如：30" type="number" name="free_wait_time" class="layui-input layui-input-inline" id="free_wait_time" value="{notempty name='$data'}{$data.free_wait_time}{/notempty}">
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">超时费用<br>（每小时）</label>
                        <div class="layui-input-block" style="max-width:500px;">
                            <input placeholder="例如：25" type="number" name="overtime_charges" class="layui-input layui-input-inline" id="overtime_charges" value="{notempty name='$data'}{$data.overtime_charges}{/notempty}">
                            <div class="layui-input-inline">
                                <select name="currency_code" id="currency_code" class="layui-select">
                                    <option value="">请选择货币单位</option>
                                    {volist name='currencyList' id='value'}
                                    <option value="{$value.currency_code}" {if isset($data.currency_code)&&$data.currency_code==$value.currency_code}selected{/if} >{$value.currency_name}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">儿童座椅说明</label>
                        <div class="layui-input-block" style="max-width:500px;">
                            <input placeholder="例如:免费提供一个" type="text" name="child_seat_desc" class="layui-input" id="child_seat_desc" value="{notempty name='$data'}{$data.child_seat_desc}{/notempty}">
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">当地时差</label>
                        <div class="layui-input-block" style="max-width:500px;">
                            <input placeholder="例如：比北京早x小时" type="text" name="localtime_diff" value="{notempty name='$data'}{$data.localtime_diff}{/notempty}" class="layui-input layui-input-inline">
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">
                            接送地址(首日) <br>
                            <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-normal addPickUpBtn">添加</a>
                        </label>
                        <blockquote id="pickUpBox" class="layui-elem-quote layui-quote-nm layui-input-block clear_float" style="min-height: 50px;width: 80%">
                            {notempty name='$data.pick_up_address_json'}
                            {volist name='$data.pick_up_address_json' id='value'}
                            <div class="layui-input-block clear_float">
                                <div class="layui-input-inline">
                                    <input autocomplete="off" placeholder="例：06:00 - 07:00" type="text" name="pick_up_time" class="layui-input layui-input-inline settimedate" value="{$value.time}">
                                </div>
                                <div class="layui-input-inline" style="width:500px;">
                                    <input placeholder="请输入接送地址" class="layui-input pick_up_address" id="pick_up_address" name="pick_up_address" value="{$value.address}">
                                    <div class="addressbox pick_up_address_box"></div>
                                    <input type="hidden" name="pick_up_address_format" value='{$value.format}'>
                                </div>
                                <div class="layui-input-inline">
                                    <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-danger delPickUpBtn">删除</a>
                                </div>
                            </div>
                            {/volist}
                            {/notempty}
                        </blockquote>
                    </div>

                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">
                            集合地址(首日) <br>
                            <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-normal addAssembleBtn">添加</a>
                        </label>
                        <blockquote id="assembleBox" class="layui-elem-quote layui-quote-nm layui-input-block clear_float" style="min-height: 50px;width: 80%">
                            {notempty name='$data.assemble_address_json'}
                            {volist name='$data.assemble_address_json' id='value'}
                            <div class="layui-input-block clear_float">
                                <div class="layui-input-inline">
                                    <input autocomplete="off" placeholder="例：06:00 - 07:00" type="text" name="assemble_time" class="layui-input layui-input-inline settimedate"  value="{$value.time}">
                                </div>
                                <div class="layui-input-inline" style="width:500px;">
                                    <input placeholder="请输入集合地址" type="text" name="assemble_address" class="layui-input"  value="{$value.address}">
                                    <div class="addressbox assemble_address_box"></div>
                                    <input type="hidden" name="assemble_address_format" value='{$value.format}'>
                                </div>
                                <div class="layui-input-inline" style="height:50px">
                                    <a href="javascript:void(0);" class="layui-btn layui-btn-sm uploadAssembleImg" id="uploadAssembleImg">上传图示</a>
                                    {if !empty($value['img']) && $imgs = explode(',',$value['img'])}
                                    {foreach name='imgs' id='img'}
                                    <div class="layui-input-inline">
                                        <img height="50" src="{$img}" alt="">
                                        <span class="colorRed delAssemblessImg">x</span>
                                        <input type="hidden" name="assemble_address_img" value='{$img}'>
                                    </div>
                                    {/foreach}
                                    {/if}
                                </div>
                                <div class="layui-input-inline">
                                    <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-danger delAssembleBtn">删除</a>
                                </div>
                            </div>
                            {/volist}
                            {/notempty}
                        </blockquote>
                    </div>

                    <!--<div class="layui-upload" id="upload-place">-->
                        <!--<label class="layui-form-label">集合地点图示</label>-->
                        <!--<button type="button" class="layui-btn" id="upload-place-img">上传</button>-->
                        <!--<div class="layui-input-" id="demoText1"></div>-->
                    <!--</div>-->
                    <!--<div class="layui-form-item layui-form-text">-->
                        <!--<label class="layui-form-label">预览图</label>-->
                        <!--<div class="layui-upload-list layui-input-block" style="width:80%">-->
                            <!--<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;min-height: 135px;">-->
                                <!--<div class="layui-upload-list" id="assembleimgsbox">-->
                                    <!--{notempty name="$data.assembleimgs"}-->
                                    <!--{volist name='$data.assembleimgs' id='value'}-->
                                    <!--<span class="assembleimgsbox">-->
                                        <!--<img width="150" class="layui-upload-img" src="{$value}">-->
                                        <!--<input type="hidden" name="assemble_address_img[]" value="{$value}">-->
                                        <!--<i class="layui-icon">ဆ</i>-->
                                    <!--</span>-->
                                    <!--{/volist}-->
                                    <!--{/notempty}-->
                                <!--</div>-->
                            <!--</blockquote>-->
                        <!--</div>-->
                    <!--</div>-->


                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">小费相关提醒</label>
                        <div class="layui-input-block" style="max-width:500px;">
                            <textarea placeholder="请输入内容" class="layui-textarea" id="tips_notice" name="tips_notice">{notempty name='$data'}{$data.tips_notice}{/notempty}</textarea>
                        </div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">门票及换票提醒</label>
                        <div class="layui-input-block" style="max-width:500px;">
                            <textarea placeholder="请输入内容" class="layui-textarea"  id="exchange_ticket_notice" name="exchange_ticket_notice">{notempty name='$data'}{$data.exchange_ticket_notice}{/notempty}</textarea>
                        </div>
                    </div>
                    <div class="layui-upload" id="upload-ticket">
                        <label class="layui-form-label">换票图示</label>
                        <button type="button" class="layui-btn" id="upload-ticket-img">上传</button>
                        <div class="layui-input-" id="demoText2"></div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">预览图</label>
                        <div class="layui-upload-list layui-input-block" style="width:80%">
                            <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;min-height: 135px;">
                                <div class="layui-upload-list" id="ticketimgsbox">
                                    {notempty name="$data.ticketimgs"}
                                    {volist name='$data.ticketimgs' id='value'}
                                        <span class="ticketimgsbox">
                                            <img width="150" class="layui-upload-img" src="{$value}">
                                            <input type="hidden" name="exchange_ticket_img[]" value="{$value}">
                                            <i class="layui-icon">ဆ</i>
                                        </span>
                                    {/volist}
                                    {/notempty}
                                </div>
                            </blockquote>
                        </div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">行程信息提醒 <br>(坑点)</label>
                        <div class="layui-input-block" style="max-width:500px;">
                            <textarea placeholder="请输入内容" class="layui-textarea"  id="trip_notice" name="trip_notice">{notempty name='$data'}{$data.trip_notice}{/notempty}</textarea>
                        </div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">酒店信息提醒</label>
                        <div class="layui-input-block" style="max-width:500px;">
                            <textarea placeholder="请输入内容" class="layui-textarea"  id="hotel_notice" name="hotel_notice">{notempty name='$data'}{$data.hotel_notice}{/notempty}</textarea>
                        </div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">接送机信息提醒</label>
                        <div class="layui-input-block" style="max-width:500px;">
                            <textarea placeholder="请输入内容" class="layui-textarea"  id="airport_notice" name="airport_notice">{notempty name='$data'}{$data.airport_notice}{/notempty}</textarea>
                        </div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">穿衣指南</label>
                        <div class="layui-input-block" style="max-width:500px;">
                            <textarea placeholder="请输入内容" class="layui-textarea"  id="clothing_notice" name="clothing_notice">{notempty name='$data'}{$data.clothing_notice}{/notempty}</textarea>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>

    <div class="layui-form-item">
        <div class="container">
            <div class="page1" style="text-align:center;">
                <button class="layui-btn" lay-submit lay-filter="updothergoodsnotice">提交</button>
            </div>
        </div>
    </div>
</div>
</body>

<script src="__PUBLIC__/layui/layui.js"></script>
<script src="__PUBLIC__/jquery/jquery.min.js"></script>
<script>

    //显示分钟时只提示 00 10 20 30 40 50
    function  formatminutes(date) {
        var showtime = $($(".laydate-time-list li ol")[1]).find("li");
        for (var i = 0; i < showtime.length; i++) {
            var t00 = showtime[i].innerText;
            if (t00 != "00" && t00 != "10" && t00 != "20" && t00 != "30" && t00 != "40" && t00 != "50") {
                showtime[i].remove()
            }
        }
        $($(".laydate-time-list li ol")[2]).find("li").remove();  //清空秒

        var showtime = $($(".laydate-time-list li ol")[4]).find("li");
        for (var i = 0; i < showtime.length; i++) {
            var t00 = showtime[i].innerText;
            if (t00 != "00" && t00 != "10" && t00 != "20" && t00 != "30" && t00 != "40" && t00 != "50") {
                showtime[i].remove()
            }
        }
        $($(".laydate-time-list li ol")[5]).find("li").remove();  //清空秒
    }
    //重新渲染时间选择器
    function resetLaydate(laydate){
        //同时绑定多个
        $('.settimedate').each(function(){
            laydate.render({
                elem: this
                ,trigger: 'click'
                ,type:'time'
                ,format:'HH:mm'
                ,range:true
                ,ready:formatminutes
            });
        });
    }
    layui.config({
        base : '__PUBLIC__/'
    }).extend({
        selectM: './multiple/selectM',
    }).use(['layer','form','jquery','selectM','laydate','table','upload'],function() {
        var layer = layui.layer,
            $ = layui.jquery,
            form = layui.form,
            upload = layui.upload,
            selectM = layui.selectM,
            laydate = layui.laydate,
            table = layui.table;
        resetLaydate(laydate);
        //增加接送地址
        $('.addPickUpBtn,.addAssembleBtn').click(function(){

            var box = $(this).parent().next();
            if($(box).attr('id')=='pickUpBox'){
                //接送地址
                var delBtn = 'delPickUpBtn';
                var time_input_name = 'pick_up_time';
                var address_input_name = 'pick_up_address';
                var address_format_input_name = 'pick_up_address_format';
                var btnId = '';
                var uploadImgdiv = '';
            }else{
                //集合地址
                var delBtn = 'delAssembleBtn';
                var time_input_name = 'assemble_time';
                var address_input_name = 'assemble_address';
                var address_format_input_name = 'assemble_address_format';
                var btnId = "uploadAssembleImg" + caculateUploadBtn();
                var uploadImgdiv = '<div class="layui-input-inline">\n' +
                    '                     <input type="hidden" name="assemble_address_img" value="">\n' +
                    '                     <a href="javascript:void(0);" class="layui-btn layui-btn-sm uploadAssembleImg" id="'+btnId+'">上传图示</a>\n' +
                    '               </div>\n';
            }
            var html = '<div class="layui-input-block clear_float">\n' +
                '                                <div class="layui-input-inline">\n' +
                '                                    <input autocomplete="off" placeholder="例：06:00 - 07:00" type="text" name="'+time_input_name+'" class="layui-input layui-input-inline settimedate" value="">\n' +
                '                                </div>\n' +
                '                                <div class="layui-input-inline" style="width:500px;">\n' +
                '                                    <input placeholder="请输入接送地址" class="layui-input" name="'+address_input_name+'" value="">\n' +
                '                                    <div class="addressbox pick_up_address_box"></div>\n' +
                '                                    <input type="hidden" name="'+address_format_input_name+'" value="">\n' +
                '                                </div>\n' + uploadImgdiv +
                '                                <div class="layui-input-inline">\n' +
                '                                    <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-danger '+delBtn+'">删除</a>\n' +
                '                                </div>\n' +
                '                            </div>';
            $(box).append(html);
            //渲染时间选择器
            resetLaydate(laydate);
            if(btnId!==''){
                bindUploadBtn(btnId)
            }
        })
        //删除地址
        $(document).on('click','.delPickUpBtn,.delAssembleBtn',function(){
            $(this).parent().parent().remove();
        })
        //执行实例
        var uploadInst = upload.render({
            elem: '#upload-place-img' //绑定元素
            ,url: "{:url('common/upload')}" //上传接口
            ,done: function(res){
                //上传完毕回调
                layer.closeAll('loading');
                if(res.code == 2) {
                    var imghtml = '<span class="assembleimgsbox">\n' +
                        '                                        <img width="150" class="layui-upload-img" src="'+res.src+'">\n' +
                        '                                        <input type="hidden" name="assemble_address_img[]" value="'+res.src+'">\n' +
                        '                                        <i class="layui-icon">ဆ</i>\n' +
                        '                                    </span>';
                    $('#assembleimgsbox').append(imghtml);
                } else {
                    layer.msg(res.msg);
                }
            }
            ,error: function(){
                //请求异常回调
                layer.closeAll('loading');
                //演示失败状态，并实现重传
                var demoText = $('#demoText1');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
            ,before:function(){
                layer.load(2); //上传loading
            }

        });

        var uploadInst2 = upload.render({
            elem: '#upload-ticket-img' //绑定元素
            ,url: "{:url('common/upload')}" //上传接口
            ,done: function(res){
                //上传完毕回调
                layer.closeAll('loading');
                if(res.code == 2) {
                    var imghtml = '<span class="ticketimgsbox">\n' +
                        '                                        <img width="150" class="layui-upload-img" src="'+res.src+'">\n' +
                        '                                        <input type="hidden" name="exchange_ticket_img[]" value="'+res.src+'">\n' +
                        '                                        <i class="layui-icon">ဆ</i>\n' +
                        '                                    </span>';
                    $('#ticketimgsbox').append(imghtml);
                } else {
                    layer.msg(res.msg);
                }
            }
            ,error: function(){
                //请求异常回调
                layer.closeAll('loading');
                //演示失败状态，并实现重传
                var demoText = $('#demoText2');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
            ,before:function(){
                layer.load(2); //上传loading
            }

        });

        function checkPickUpAddressData()
        {
            var pick_up_address_arr = [];
            var stopFlag = false;
            $('#pickUpBox .layui-input-block').each(function (i,v) {
                var pick_up_time = $(v).find('input[name=pick_up_time]').val();
                if(pick_up_time=='' || pick_up_time==undefined){
                    layer.msg('请补充完所有的接送时间');
                    stopFlag = true;
                    return false;
                }
                var pick_up_address = $(v).find('input[name=pick_up_address]').val();
                if(pick_up_address=='' || pick_up_address==undefined){
                    layer.msg('请补充完所有的接送地址');
                    stopFlag = true;
                    return false;
                }
                var pick_up_address_format = $(v).find('input[name=pick_up_address_format]').val();
                if(pick_up_address_format!=''){
                    pick_up_address_format = JSON.parse(pick_up_address_format);
                }
                pick_up_address_arr.push({'time':pick_up_time,'address':pick_up_address,'format':pick_up_address_format});
            })
            if(stopFlag){
                return false;
            }
            if(pick_up_address_arr.length>0){
                var pick_up_address_json = JSON.stringify(pick_up_address_arr);
            }else{
                var pick_up_address_json = '';
            }
            return pick_up_address_json;
        }

        function checkAssembleAddressData()
        {
            var assemble_address_arr = [];
            var stopFlag = false;
            $('#assembleBox .layui-input-block').each(function (i,v) {
                var assemble_time = $(v).find('input[name=assemble_time]').val();
                if(assemble_time=='' || assemble_time==undefined){
                    layer.msg('请补充完所有的集合时间');
                    stopFlag = true;
                    return false;
                }
                var assemble_address = $(v).find('input[name=assemble_address]').val();
                if(assemble_address=='' || assemble_address==undefined){
                    layer.msg('请补充完所有的集合地址');
                    stopFlag = true;
                    return false;
                }
                var assemble_address_format = $(v).find('input[name=assemble_address_format]').val();
                var assemble_address_img = $(v).find('input[name=assemble_address_img]');
                if(assemble_address_img.length>1){
                    var imgs = [];
                    $.each(assemble_address_img,function (i,v) {
                        if($(v).val()!==''){
                            imgs.push($(v).val());
                        }
                    })
                    assemble_address_img = imgs.join(',');
                }else{
                    assemble_address_img = $(assemble_address_img).val();
                }
                if(assemble_address_format!=''){
                    assemble_address_format = JSON.parse(assemble_address_format);
                }
                assemble_address_arr.push({'time':assemble_time,'address':assemble_address,'format':assemble_address_format,'img':assemble_address_img});
            })
            if(stopFlag){
                return false;
            }
            if(assemble_address_arr.length>0){
                var assemble_address_json = JSON.stringify(assemble_address_arr);
            }else{
                var assemble_address_json = '';
            }
            return assemble_address_json;
        }
        //提交数据
        form.on('submit(updothergoodsnotice)', function (data) {
            var pick_up_address = checkPickUpAddressData();
            if(pick_up_address===false){
                return false;
            }
            var assemble_address = checkAssembleAddressData();
            if(assemble_address===false){
                return false;
            }
            var postdata = $('#tripconfig').serialize();

            //特殊字符处理
            pick_up_address = pick_up_address.replace(/&/g,'replace_and');
            assemble_address = assemble_address.replace(/&/g,'replace_and');
            postdata += "&pick_up_address_json=" + pick_up_address;
            postdata += "&assemble_address_json=" + assemble_address;
            $.ajax({
                url: "{:url('admin/goods/updothergoodsnotice',['id'=>$id])}",
                data: postdata,
                type: 'post',
                async: false,
                success: function (res) {
                    layer.msg(res.msg);
                    if (res.code > 0) {
                        setTimeout(function () {
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                        }, 1000)
                    }
                }
            })
        });


        //第一步解析地址
        var googleMapData = [];
//如果详细地址未匹配到信息则使用列表中的数据
        function setAddressByList(res,googleMapData,address)
        {
            if(res.data.candidates.length < 1 || "OK" != res.data.status){
                if(googleMapData.length > 0){
                    $.each(googleMapData,function (i,v) {
                        if(v.formatted_address==address){
                            $.ajaxSettings.async = false;
                            $.post('{:url("/api/common/getGoogleImgByLatLng")}',{
                                lat:v.geometry.location.lat,
                                lng:v.geometry.location.lng,
                                zoom:8
                            },function (img_res) {
                                if(img_res.code>0){
                                    res.data.google_map_img = img_res.data.google_map_img;
                                    res.data.status = 'OK';
                                }
                            },'json')
                            $.ajaxSettings.async = true;
                            res.data.candidates.push(v);return false;
                        }
                    })
                }
            }

            return res;
        }

        function setAddress(address,address_input,address_format_input) {
            console.log(address,address_input);

            //切换成接口访问
            $.post('{:url("/api/common/getGoogleAddressList")}',{address:address,getMap:true},function (res) {
                if(res.code>0){
                    var res = setAddressByList(res,googleMapData,address);
                    var candidates = res.data.candidates;
                    if(candidates.length>0 && "OK" == res.data.status){
                        var address_json = formattedAddressToOrder(candidates[0]);
                        address_input.val(address);
                        address_format_input.val(address_json);
                        $("#map img").attr('src',res.data.google_map_img);
                    }
                }
            },'json')
        }
        //用地址结果请求继续解析地址
        function getAddressList(_that) {
            var address = _that.val();
            var addressbox="";
            if(address=='' || address==undefined){
                return false;
            }
            //切换成接口访问
            $.post('{:url("/api/common/getGoogleAddressList")}',{address:address},function (res) {
                if(res.code>0){
                    var candidates = res.data.candidates;
                    googleMapData = res.data.candidates;
                    if(candidates.length > 0 && "OK" == res.data.status){
                        $.each(candidates,function (i,v) {
                            if(i>4){
                                return false;
                            }
                            addressbox+="<span>"+v.formatted_address+"</span>";
                        })
                        console.log(addressbox);
                        _that.next().html(addressbox);
                    }
                }
            },'json')
        }
        //传入谷歌地址的数据结构
        function formattedAddressToOrder(address) {
            var formatt = {
                "arbitrary":{
                    "geocoded":{
                        "name":address.name,
                        "addr":address.formatted_address,
                        "lat":address.geometry.location.lat,
                        "lng":address.geometry.location.lng,
                        "gid":address.place_id,
                    }
                }
            };
            return JSON.stringify(formatt);
        }
        var timeoutId = 0;
        //地址输入绑定事件
        $(document).on('input','input[name=pick_up_address],input[name=assemble_address]',function () {
            // console.log($(this).val())
            resetAddressBox();
            //添加addressbox
            clearTimeout(timeoutId);
            var value = $(this);
            timeoutId = setTimeout(function(){
                getAddressList(value);
            },1000)
        })


        $(document).on("click",".addressbox span",function(){
            var address = $(this).html();
            //查找当前需要赋值的input
            var addressBox = $(this).parent();
            var addressInput = $(addressBox).prev();
            var addressFormatInput = $(addressBox).next();
            setAddress(address,addressInput,addressFormatInput);
            //删除addressbox
            resetAddressBox();
        });

        $(document).on("click",'*:not(.addressbox_span)',function(event){
            resetAddressBox();
        })

        function resetAddressBox()
        {
            $(".addressbox").html('');
        }
        //添加集合地址图示
        function addAssembleImg(_that,src)
        {
            var html = '<div class="layui-input-inline">\n' +
                '                                        <img height="50" src="'+src+'" alt="">\n' +
                '                                        <span class="colorRed delAssemblessImg">x</span>\n' +
                '                                    <input type="hidden" name="assemble_address_img" value="'+src+'">' +
                '                                    </div>';
            var parent = $(_that).parent();
            // $(_that).hide();
            parent.append(html);
            // parent.find('input[name=assemble_address_img]').val(src);
        }
        //删除集合地点图示
        function delAssembleImg(_that)
        {
            // $(_that).parent().parent().find("input[name=assemble_address_img]").val('');
            // $(_that).parent().parent().find(".uploadAssembleImg").show();
            $(_that).parent().remove();
        }
        //计算上传按钮的个数
        function caculateUploadBtn() {
            return $('.uploadAssembleImg').length + 1;
        }
        //初始化绑定上传按钮
        $.each($('.uploadAssembleImg'),function (i,v) {
            var btnId = 'uploadAssembleImg' + (i+1);
            $(v).attr('id',btnId);
            bindUploadBtn(btnId);
        })
        //绑定图片上传元素
        function bindUploadBtn(element)
        {
            var elem = '#'+element;
            upload.render({
                elem: elem //绑定元素
                ,url: "{:url('common/upload')}" //上传接口
                ,done: function(res,index,upload){
                    var src = replaceDomain(res.src);
                    addAssembleImg($(elem),src);
                }
            });
        }

        //删除图示
        $(document).on('click','.delAssemblessImg',function(){
            delAssembleImg(this);
        })
        //图片域名替换
        function replaceDomain(src)
        {
            return src.replace('kwibon-public-images.oss-cn-beijing.aliyuncs.com','i.kuaibangxing.com');
        }
    })
</script>
<!-- 配置文件 -->
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">

    var ue5 = UE.getEditor('tips_notice',{
        initialFrameHeight: 100,
        initialFrameWidth: 500,
        toolbars:[
            ['fullscreen', 'source', 'undo', 'redo'],
            ['bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc']
        ]
    });
    var ue6 = UE.getEditor('exchange_ticket_notice',{
        initialFrameHeight: 100,
        initialFrameWidth: 500,
        toolbars:[
            ['fullscreen', 'source', 'undo', 'redo'],
            ['bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc']
        ]
    });
    var ue7 = UE.getEditor('trip_notice',{
        initialFrameHeight: 100,
        initialFrameWidth: 500,
        toolbars:[
            ['fullscreen', 'source', 'undo', 'redo'],
            ['bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc']
        ]
    });
    var ue8 = UE.getEditor('hotel_notice',{
        initialFrameHeight: 100,
        initialFrameWidth: 500,
        toolbars:[
            ['fullscreen', 'source', 'undo', 'redo'],
            ['bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc']
        ]
    });
    var ue9 = UE.getEditor('airport_notice',{
        initialFrameHeight: 100,
        initialFrameWidth: 500,
        toolbars:[
            ['fullscreen', 'source', 'undo', 'redo'],
            ['bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc']
        ]
    });
    var ue10 = UE.getEditor('clothing_notice',{
        initialFrameHeight: 100,
        initialFrameWidth: 500,
        toolbars:[
            ['fullscreen', 'source', 'undo', 'redo'],
            ['bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc']
        ]
    });

</script>

<script>
    //放大图片
    $(document).on('click',"img",function(){
        var that = this;
        amplificationImg(that);
    })

    function amplificationImg(that) {
        var url = $(that).attr("src");
        if(url=="" || url==undefined){
            return false;
        }
        layer.open({
            type: 1,
            title: false,
            closeBtn: 0,
            shadeClose: true,
            area: ['400px'], //宽高
            content: "<img width='400' src=" + url + " />"
        });
    }
    //删除节点
    $('#assembleimgsbox').on('click','.layui-icon',function(){
        $(this).parent().remove();
    })
    //删除节点
    $('#ticketimgsbox').on('click','.layui-icon',function(){
        $(this).parent().remove();
    })


</script>

</html>